<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="应用id" prop="appId">
      <el-input v-model="dataForm.appId" placeholder="应用id"></el-input>
    </el-form-item>
    <el-form-item label="应用密码要求等级1，2，3，4" prop="appLevel">
      <el-input v-model="dataForm.appLevel" placeholder="应用密码要求等级1，2，3，4"></el-input>
    </el-form-item>
    <el-form-item label="评论类型1.风评2.密评" prop="assessmentType">
      <el-input v-model="dataForm.assessmentType" placeholder="评论类型1.风评2.密评"></el-input>
    </el-form-item>
    <el-form-item label="风评时间" prop="assessmentDate">
      <el-input v-model="dataForm.assessmentDate" placeholder="风评时间"></el-input>
    </el-form-item>
    <el-form-item label="控制点1" prop="splitTypeOne">
      <el-input v-model="dataForm.splitTypeOne" placeholder="控制点1"></el-input>
    </el-form-item>
    <el-form-item label="控制点1" prop="splitTypeDescOne">
      <el-input v-model="dataForm.splitTypeDescOne" placeholder="控制点1"></el-input>
    </el-form-item>
    <el-form-item label="控制点2" prop="splitTypeTwo">
      <el-input v-model="dataForm.splitTypeTwo" placeholder="控制点2"></el-input>
    </el-form-item>
    <el-form-item label="控制点2" prop="splitTypeDescTwo">
      <el-input v-model="dataForm.splitTypeDescTwo" placeholder="控制点2"></el-input>
    </el-form-item>
    <el-form-item label="控制点3" prop="splitTypeThree">
      <el-input v-model="dataForm.splitTypeThree" placeholder="控制点3"></el-input>
    </el-form-item>
    <el-form-item label="控制点3" prop="splitTypeDescThree">
      <el-input v-model="dataForm.splitTypeDescThree" placeholder="控制点3"></el-input>
    </el-form-item>
    <el-form-item label="等级监控描述" prop="levelMsg">
      <el-input v-model="dataForm.levelMsg" placeholder="等级监控描述"></el-input>
    </el-form-item>
    <el-form-item label="结果" prop="resultType">
      <el-input v-model="dataForm.resultType" placeholder="结果"></el-input>
    </el-form-item>
    <el-form-item label="结果描述" prop="resultTypeDesc">
      <el-input v-model="dataForm.resultTypeDesc" placeholder="结果描述"></el-input>
    </el-form-item>
    <el-form-item label="符合" prop="conform">
      <el-input v-model="dataForm.conform" placeholder="符合"></el-input>
    </el-form-item>
    <el-form-item label="部分符合" prop="partialConform">
      <el-input v-model="dataForm.partialConform" placeholder="部分符合"></el-input>
    </el-form-item>
    <el-form-item label="不符合" prop="unConform">
      <el-input v-model="dataForm.unConform" placeholder="不符合"></el-input>
    </el-form-item>
    <el-form-item label="不适用" prop="inconformity">
      <el-input v-model="dataForm.inconformity" placeholder="不适用"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createDate">
      <el-input v-model="dataForm.createDate" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="状态0:无效，1 有效" prop="status">
      <el-input v-model="dataForm.status" placeholder="状态0:无效，1 有效"></el-input>
    </el-form-item>
    <el-form-item label="唯一码" prop="uniqueId">
      <el-input v-model="dataForm.uniqueId" placeholder="唯一码"></el-input>
    </el-form-item>
    <el-form-item label="文件地址" prop="filePath">
      <el-input v-model="dataForm.filePath" placeholder="文件地址"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          appId: '',
          appLevel: '',
          assessmentType: '',
          assessmentDate: '',
          splitTypeOne: '',
          splitTypeDescOne: '',
          splitTypeTwo: '',
          splitTypeDescTwo: '',
          splitTypeThree: '',
          splitTypeDescThree: '',
          levelMsg: '',
          resultType: '',
          resultTypeDesc: '',
          conform: '',
          partialConform: '',
          unConform: '',
          inconformity: '',
          createDate: '',
          status: '',
          uniqueId: '',
          filePath: ''
        },
        dataRule: {
          appId: [
            { required: true, message: '应用id不能为空', trigger: 'blur' }
          ],
          appLevel: [
            { required: true, message: '应用密码要求等级1，2，3，4不能为空', trigger: 'blur' }
          ],
          assessmentType: [
            { required: true, message: '评论类型1.风评2.密评不能为空', trigger: 'blur' }
          ],
          assessmentDate: [
            { required: true, message: '风评时间不能为空', trigger: 'blur' }
          ],
          splitTypeOne: [
            { required: true, message: '控制点1不能为空', trigger: 'blur' }
          ],
          splitTypeDescOne: [
            { required: true, message: '控制点1不能为空', trigger: 'blur' }
          ],
          splitTypeTwo: [
            { required: true, message: '控制点2不能为空', trigger: 'blur' }
          ],
          splitTypeDescTwo: [
            { required: true, message: '控制点2不能为空', trigger: 'blur' }
          ],
          splitTypeThree: [
            { required: true, message: '控制点3不能为空', trigger: 'blur' }
          ],
          splitTypeDescThree: [
            { required: true, message: '控制点3不能为空', trigger: 'blur' }
          ],
          levelMsg: [
            { required: true, message: '等级监控描述不能为空', trigger: 'blur' }
          ],
          resultType: [
            { required: true, message: '结果不能为空', trigger: 'blur' }
          ],
          resultTypeDesc: [
            { required: true, message: '结果描述不能为空', trigger: 'blur' }
          ],
          conform: [
            { required: true, message: '符合不能为空', trigger: 'blur' }
          ],
          partialConform: [
            { required: true, message: '部分符合不能为空', trigger: 'blur' }
          ],
          unConform: [
            { required: true, message: '不符合不能为空', trigger: 'blur' }
          ],
          inconformity: [
            { required: true, message: '不适用不能为空', trigger: 'blur' }
          ],
          createDate: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '状态0:无效，1 有效不能为空', trigger: 'blur' }
          ],
          uniqueId: [
            { required: true, message: '唯一码不能为空', trigger: 'blur' }
          ],
          filePath: [
            { required: true, message: '文件地址不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/sys/subappassessmentsplit/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.appId = data.subAppAssessmentSplit.appId
                this.dataForm.appLevel = data.subAppAssessmentSplit.appLevel
                this.dataForm.assessmentType = data.subAppAssessmentSplit.assessmentType
                this.dataForm.assessmentDate = data.subAppAssessmentSplit.assessmentDate
                this.dataForm.splitTypeOne = data.subAppAssessmentSplit.splitTypeOne
                this.dataForm.splitTypeDescOne = data.subAppAssessmentSplit.splitTypeDescOne
                this.dataForm.splitTypeTwo = data.subAppAssessmentSplit.splitTypeTwo
                this.dataForm.splitTypeDescTwo = data.subAppAssessmentSplit.splitTypeDescTwo
                this.dataForm.splitTypeThree = data.subAppAssessmentSplit.splitTypeThree
                this.dataForm.splitTypeDescThree = data.subAppAssessmentSplit.splitTypeDescThree
                this.dataForm.levelMsg = data.subAppAssessmentSplit.levelMsg
                this.dataForm.resultType = data.subAppAssessmentSplit.resultType
                this.dataForm.resultTypeDesc = data.subAppAssessmentSplit.resultTypeDesc
                this.dataForm.conform = data.subAppAssessmentSplit.conform
                this.dataForm.partialConform = data.subAppAssessmentSplit.partialConform
                this.dataForm.unConform = data.subAppAssessmentSplit.unConform
                this.dataForm.inconformity = data.subAppAssessmentSplit.inconformity
                this.dataForm.createDate = data.subAppAssessmentSplit.createDate
                this.dataForm.status = data.subAppAssessmentSplit.status
                this.dataForm.uniqueId = data.subAppAssessmentSplit.uniqueId
                this.dataForm.filePath = data.subAppAssessmentSplit.filePath
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/sys/subappassessmentsplit/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'appId': this.dataForm.appId,
                'appLevel': this.dataForm.appLevel,
                'assessmentType': this.dataForm.assessmentType,
                'assessmentDate': this.dataForm.assessmentDate,
                'splitTypeOne': this.dataForm.splitTypeOne,
                'splitTypeDescOne': this.dataForm.splitTypeDescOne,
                'splitTypeTwo': this.dataForm.splitTypeTwo,
                'splitTypeDescTwo': this.dataForm.splitTypeDescTwo,
                'splitTypeThree': this.dataForm.splitTypeThree,
                'splitTypeDescThree': this.dataForm.splitTypeDescThree,
                'levelMsg': this.dataForm.levelMsg,
                'resultType': this.dataForm.resultType,
                'resultTypeDesc': this.dataForm.resultTypeDesc,
                'conform': this.dataForm.conform,
                'partialConform': this.dataForm.partialConform,
                'unConform': this.dataForm.unConform,
                'inconformity': this.dataForm.inconformity,
                'createDate': this.dataForm.createDate,
                'status': this.dataForm.status,
                'uniqueId': this.dataForm.uniqueId,
                'filePath': this.dataForm.filePath
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
